export default {
  state() {
    // 从本地存储恢复语言设置
    let language = "zh";
    if (typeof window !== 'undefined') {
      try {
        if (typeof $.db !== 'undefined') {
          language = $.db.get("language") || "zh";
        }
      } catch (e) {
        console.warn('获取语言设置失败:', e);
      }
    }
    
    return {
      active_index: 1,
	  auth: [],
      language: language // 'zh' 中文, 'en' 英文
    }
  },
  mutations: {
    set_alert(state, obj) {
      state.alert = Object.assign(state.alert, obj);
    },
	set_auth(state,list){
		state.auth = list;
	},
	set_language(state, lang) {
		state.language = lang;
		// 保存到本地存储
		if (typeof $.db !== 'undefined') {
			$.db.set("language", lang, 365); // 保存365天
		}
	}
  }
}
